package com.example.su_shi_tan_mine.child.provider

import android.content.Context
import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.su_shi_tan_bas_lib.adapter.JssBaseViewHolder
import com.example.su_shi_tan_bas_lib.adapter.multi22.Basic.JssBaseItemProvider
import com.example.su_shi_tan_bas_lib.glidmodule.GlideApp
import com.example.su_shi_tan_mine.R
import com.example.su_shi_tan_mine.child.bean.PayingWayListBean
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.ImageViewerPopupView
import com.lxj.xpopup.interfaces.XPopupImageLoader
import java.io.File

class PayingWayListALiPayProvider: JssBaseItemProvider<PayingWayListBean?, JssBaseViewHolder>(){
    override val itemViewType: Int
        get() =  PayingWayListBean.a_li_pay
    override val layoutId: Int
        get() = R.layout.paying_way_list_a_li_pay_provider

    override fun onViewHolderCreated(viewHolder: JssBaseViewHolder, viewType: Int) {
        super.onViewHolderCreated(viewHolder, viewType)
        addChildClickViewIds(R.id.aliPayCode)
    }

    override fun convert(helper: JssBaseViewHolder?, item: PayingWayListBean?) {
        helper
            ?.setText(R.id.aliPayAccount,item?.number)
            ?.setText(R.id.aliPayRelName,item?.real_name)
            ?.setImageNetUrl(R.id.aliPayCode,item?.qrcode_url)
    }

    override fun onChildClick(
        helper: BaseViewHolder,
        view: View,
        data: PayingWayListBean?,
        position: Int
    ) {
        super.onChildClick(helper, view, data, position)
        when(view.id){
            R.id.aliPayCode->{
                val imageViewerPopupView = ImageViewerPopupView(context)
                imageViewerPopupView.setImageUrls(listOf(data?.qrcode_url))
                imageViewerPopupView.setXPopupImageLoader(object : XPopupImageLoader {
                    override fun loadImage(position: Int, uri: Any, imageView: ImageView) {
                        GlideApp.with(context)
                            .load(uri)
                            .centerCrop()
                            .into(imageView)
                    }

                    override fun getImageFile(context: Context, uri: Any): File {
                        return File(uri.toString())
                    }
                })
                XPopup.Builder(context)
                    .asCustom(imageViewerPopupView)
                    .show()
            }
        }
    }
}